﻿using System;
using System.Collections;
using System.Xml;
using System.Xml.XPath;
using java = biz.ritter.javapi;
using biz.ritter.javapi.util;

namespace biz.ritter.javapi.xml
{
    /// <summary>
    /// Branch
    /// </summary>
    [Serializable]
    public class Branch : ICloneable, IXPathNavigable
    {
        private XmlNode delegateInstance;
        
        /// <summary>
        /// Branch
        /// </summary>
        /// <param name="node"></param>
        public Branch(XmlNode node)
        {
            this.delegateInstance = node;
        }


        /// <summary>
        /// User-defined conversion from Branch to XmlNode 
        /// </summary>
        /// <param name="branch"></param>
        /// <returns></returns>
        public static implicit operator XmlNode(Branch branch)
        {
            return branch.delegateInstance;
        }

        //  
        /// <summary>
        /// User-defined conversion from Branch to XmlNode
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static implicit operator Branch(XmlNode node)
        {
            return new Branch(node);
        }

        /// <summary>
        /// Iterator<Branch>
        /// </summary>
        /// <returns></returns>
        public Iterator<Branch> nodeIterator()
        {
            LinkedList<Branch> list = new LinkedList<Branch>();
            XmlNode node = this.delegateInstance.NextSibling;
            while (node != null)
            {
                list.add(new Branch(node));
                node = node.NextSibling;
            }
            return list.iterator();
        }

        /// <summary>
        /// Clone()
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            return this.delegateInstance.Clone();
        }

        /// <summary>
        /// CreateNavigator
        /// </summary>
        /// <returns></returns>
        public XPathNavigator CreateNavigator()
        {
            return this.delegateInstance.CreateNavigator();
        }

        /// <summary>
        /// getText
        /// </summary>
        /// <returns></returns>
        public String getText()
        {
            return this.delegateInstance.InnerText;
        }

        /// <summary>
        /// InnerText
        /// </summary>
        public String InnerText
        {
            get
            {
                return this.delegateInstance.InnerText;
            }
            set
            {
                this.delegateInstance.InnerText = value;
            }
        }

        /// <summary>
        /// getName
        /// </summary>
        /// <returns></returns>
        public String getName()
        {
            return this.delegateInstance.LocalName;
        }

        /// <summary>
        /// LocalName
        /// </summary>
        public String LocalName
        {
            get
            {
                return this.delegateInstance.LocalName;
            }
        }
             

        /// <summary>
        /// OwnerDocument
        /// </summary>
        public XmlDocument OwnerDocument
        {
            get
            {
                return this.delegateInstance.OwnerDocument;
            }
        }

        /// <summary>
        /// AppendChild
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public Branch AppendChild(XmlNode node)
        {
            return this.delegateInstance.AppendChild(node);
        }

    }
}
